home *** CD-ROM | disk | FTP | other *** search
- Path: usenet.cis.ufl.edu!caen!hasdi
- From: hasdi@news-server.engin.umich.edu (HASDI RODZMANN HASHIM)
- Newsgroups: comp.lang.c
- Subject: Do you have ever pass structures?
- Date: 21 Feb 1996 04:56:50 GMT
- Organization: University of Michigan Engineering, Ann Arbor
- Message-ID: <4ge8mi$qjm@srvr1.engin.umich.edu>
- NNTP-Posting-Host: hasdi@date.engin.umich.edu
- X-Newsreader: TIN [version 1.2 PL2]
-
- As I gain more and more experience in writing C code (sure), I find
- myself passing more and more information and returning even more.
- This is where using structures become handy.
-
- MY QUESTION is do you ever pass the whole structures to a function
- or you just pass a pointer to a function? For example, for a struct
- of the following size...
-
- struct _bar {
- int a;
- int b;
- float c;
- double d;
- char e[100];
- }
-
- typedef _bar bar;
-
- I find myself writing...
- void foo(bar *a)
- instead of
- void foo(bar)
-
- If I want to avoid bar from being modified, one limited way to do
- it is to add the CONST qualifier.
- void foo(const bar *a)
-
- So is there any REAL advantage is passing an entire structure? Do people
- ever do it? I've some people's source code and almost always, they
- pass pointers to structures instead of the structure itself. In a way,
- passing a pointer to an array instead of the array itself might be
- feature not a bug in C. :)
-
- Thank you!
-
- Hasdi
-